package com.qijian.tool.domain.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.qijian.common.utils.ObjectUtils;
import lombok.Data;

import java.math.BigDecimal;
import java.math.RoundingMode;

@Data
public class BenefitReportVo {
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String month;
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private BigDecimal benefit;
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private BigDecimal materialTotal;
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private BigDecimal normArtificial;
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private BigDecimal outsourcingTotal;
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private BigDecimal freightTotal;
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private BigDecimal income;
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private BigDecimal lmMaterialTotal;
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private BigDecimal lmNormArtificial;
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private BigDecimal lmOutsourcingTotal;
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private BigDecimal lmFreightTotal;
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private BigDecimal lmIncome;
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String itemName;
    private String bomId;

    public BigDecimal getBenefit() {
        if(ObjectUtils.isNull(benefit)){
            return BigDecimal.ZERO;
        }
        return benefit.multiply(new BigDecimal(100)).setScale(2, RoundingMode.HALF_UP);
    }

    public BigDecimal getMom() {
        BigDecimal lmBenefit = lmIncome.subtract(lmMaterialTotal).subtract(lmNormArtificial).subtract(lmOutsourcingTotal).subtract(lmFreightTotal);
        if (lmIncome.compareTo(BigDecimal.ZERO) == 0 || lmBenefit.compareTo(BigDecimal.ZERO) == 0) {
            return BigDecimal.ZERO;
        }
        return lmBenefit.divide(lmIncome, RoundingMode.HALF_UP).multiply(new BigDecimal(100)).setScale(2, RoundingMode.HALF_UP);
    }
}
